//
//  CourseListCell.m
//  KeepProject
//
//  Created by amos on 16/1/20.
//  Copyright © 2016年 itheima. All rights reserved.
//

#import "CoursePlanCell.h"
#import "UIView+UIFrame.h"
@interface CoursePlanCell ()
@property (weak, nonatomic) IBOutlet UILabel* planeNameLabel;
@property (weak, nonatomic) IBOutlet UIImageView* iconView;

@property (weak, nonatomic) IBOutlet UILabel* forceNmaeLabel;
@property (weak, nonatomic) IBOutlet UIView* starsView;
@property (weak, nonatomic) IBOutlet UILabel* equipmentLabel;
@property (weak, nonatomic) IBOutlet UILabel* durationLabel;
@property (weak, nonatomic) IBOutlet UILabel* partLabel;
@property (weak, nonatomic) IBOutlet UILabel* membersNumberLabel;

@end

@implementation CoursePlanCell

- (void)awakeFromNib
{
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setPlan:(CoursePlan*)plan
{
    _plan = plan;

    _planeNameLabel.text = plan.name;

    _forceNmaeLabel.text = plan.forceName;
    _equipmentLabel.text = plan.equipment;

    _durationLabel.text = [NSString stringWithFormat:@"%d %@", plan.duration.intValue, [plan.type isEqualToString:@"group"] ? @"天" : @"分钟"];

    _partLabel.text = plan.part;
    _membersNumberLabel.text = [NSString stringWithFormat:@"已有%d人参加", plan.members.intValue];

    if (plan.icon) {
        _iconView.image = [UIImage imageNamed:plan.icon];
    }

    for (NSInteger i = 1; i < 6; i++) {

        NSString* imageName = nil;
        if (i < plan.force.intValue) {
            imageName = @"force_on";
        }
        else {
            imageName = @"force_white";
        }
        UIImageView* imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:imageName]];
        //[imageView sizeToFit];
        imageView.width = _starsView.width * 0.2 - 5;
        imageView.height = _starsView.height;
        imageView.x = imageView.width * (i - 1) + 5;
        [_starsView addSubview:imageView];
    }
}
@end
